const { request } = require('./request');

const baseApi = "/api/admin/mp/commission/"
const api = {
  // 分销中心相关接口
  getCommissionList: baseApi + '/list',        // 佣金列表
  getWithdrawList: baseApi + '/list_withdraw', 
  getCommissionDetails: baseApi + '/details',  // 佣金明细
  getUserStats: '/api/distribution/user/stats',                  // 用户统计数据
  applyWithdrawal: baseApi + '/apply_withdraw',          // 提现申请
  checkAdminPermission: '/api/distribution/check-permission',    // 检查权限
  getBalance: baseApi + '/balance',
  get_qrcode:'/api/get_qrcode'
};

// 发送请求函数（可以共用之前的sendRequest，也可以复用request方法）

const commissionApi = {
  // 获取佣金列表
  getCommissionList(params = {}) {
    // GET请求，拼接参数
    const query = Object.entries(params)
      .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
      .join('&');
    return request(`${api.getCommissionList}?${query}`, 'GET');
  },
  // 获取佣金列表
  getWithdrawList(params = {}) {
    // GET请求，拼接参数
    const query = Object.entries(params)
      .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
      .join('&');
    return request(`${api.getWithdrawList}?${query}`, 'GET');
  },
  // 获取佣金明细
  getCommissionDetails(params = {}) {
    const query = Object.entries(params)
      .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
      .join('&');
    return request(`${api.getCommissionDetails}?${query}`, 'GET');
  },

  // 用户统计数据
  getUserStats(userId) {
    return request(`${api.getUserStats}?user_id=${userId}`, 'GET');
  },


  getBalance(){
    return request(`${api.getBalance}`, 'GET');
  },

  // 提现申请
  applyWithdrawal(data) {
    return request(api.applyWithdrawal, 'POST', data);
  },

  // 检查管理员权限
  checkPermission(userId) {
    return request(`${api.checkAdminPermission}?user_id=${userId}`, 'GET');
  },

  get_qrcode(){
    return request(`${api.get_qrcode}`, 'GET');
  },
};

module.exports = commissionApi;